package mylab.starters.uuid.config;

import lombok.Data;
import lombok.EqualsAndHashCode;
import mylab.utils.spring.spi.AbstractProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;

import static mylab.utils.spring.constants.PropertyConst.PROPERTIES_PREFIX;

@Data
@ConfigurationProperties(prefix = UuidProperties.PREFIX)
public class UuidProperties {

    public static final String PREFIX = PROPERTIES_PREFIX + ".uuid";
    private static final String BUSINESS_NAME = "[businessName]";

    private ReidsUuidProperties redis = new ReidsUuidProperties();
    private MysqlUuidProperties mysql = new MysqlUuidProperties();
    private SnowflakeUuidProperties snowflake = new SnowflakeUuidProperties();


    @Data
    @EqualsAndHashCode(callSuper = true)
    public static class ReidsUuidProperties extends BaseIdProperties {
        /**
         * Redis IP
         */
        private String ip;

        /**
         * Redis 端口
         */
        private int port;

        /**
         * Redis 密码
         */
        private String password;

        /**
         * 获取range步长[可选，默认：1000]
         */
        private int step = 1000;

        /**
         * 序列号分配起始值[可选：默认：0]
         */
        private long stepStart = 0;

        /**
         * 业务名称
         */
        private String businessName = BUSINESS_NAME;
    }

    @Data
    @EqualsAndHashCode(callSuper = true)
    public static class MysqlUuidProperties extends BaseIdProperties {
        /**
         * 表名称
         */
        private String tableName = "uuid";
        /**
         * 重试次数
         */
        private int retryTimes = 1;

        /**
         * 获取range步长[可选，默认：1000]
         */
        private int step = 1000;

        /**
         * 序列号分配起始值[可选：默认：0]
         */
        private long stepStart = 0;

        /**
         * 业务名称
         */
        private String businessName = BUSINESS_NAME;
    }

    @Data
    @EqualsAndHashCode(callSuper = true)
    public static class SnowflakeUuidProperties extends BaseIdProperties {
        /**
         * 数据中心ID，值的范围在[0,31]之间，一般可以设置机房的IDC[必选]
         */
        private long dataCenterId;
        /**
         * 工作机器ID，值的范围在[0,31]之间，一般可以设置机器编号[必选]
         */
        private long workerId;
    }

    @Data
    @EqualsAndHashCode(callSuper = true)
    public static class BaseIdProperties extends AbstractProperties {
        /**
         * 前缀
         */
        private String prefix = "";
    }
}
